<template>
  <div class="product-card" @click="handleClick">
    <div class="product-image">
      <img :src="product.image" :alt="product.name" class="w-full h-48 object-cover">
    </div>
    <div class="product-content">
      <div class="product-header">
        <h3 class="product-title">{{ product.name }}</h3>
        <span :class="['product-badge', getBadgeClass(product.category)]">{{ product.category }}</span>
      </div>
      <p class="product-description">{{ product.description }}</p>
      <div class="product-footer">
        <span class="product-price">{{ product.price }}</span>
        <button class="buy-button" @click.stop="handleBuy">立即购买</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ProductCard',
  props: {
    product: {
      type: Object,
      required: true
    }
  },
  methods: {
    handleClick() {
      this.$router.push(`/product/${this.product.id}`)
    },
    handleBuy() {
      // 这里可以添加购买逻辑
      this.$message.success('已添加到购物车')
    },
    getBadgeClass(category) {
      const badgeClasses = {
        '热销中': 'badge-hot',
        '9成新': 'badge-used',
        '现烤': 'badge-fresh',
        '二手': 'badge-second',
        '全新': 'badge-new',
        '手工制作': 'badge-handmade'
      }
      return badgeClasses[category] || 'badge-default'
    }
  }
}
</script>

<style lang="scss" scoped>
.product-card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
  transition: transform 0.2s;
  overflow: hidden;
  cursor: pointer;
  
  &:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.1);
  }
  
  .product-image {
    width: 100%;
    height: 192px;
    overflow: hidden;
    
    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      transition: transform 0.3s ease;
    }
  }
  
  &:hover .product-image img {
    transform: scale(1.05);
  }
  
  .product-content {
    padding: 1rem;
  }
  
  .product-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
  }
  
  .product-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: #1f2937;
    line-height: 1.4;
    flex: 1;
    margin-right: 0.5rem;
  }
  
  .product-badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-weight: 500;
    white-space: nowrap;
    
    &.badge-hot {
      background-color: #fef2f2;
      color: #dc2626;
    }
    
    &.badge-used {
      background-color: #fff7ed;
      color: #ea580c;
    }
    
    &.badge-fresh {
      background-color: #f0fdf4;
      color: #16a34a;
    }
    
    &.badge-second {
      background-color: #eff6ff;
      color: #2563eb;
    }
    
    &.badge-new {
      background-color: #eff6ff;
      color: #2563eb;
    }
    
    &.badge-handmade {
      background-color: #f0fdf4;
      color: #16a34a;
    }
    
    &.badge-default {
      background-color: #f3f4f6;
      color: #6b7280;
    }
  }
  
  .product-description {
    color: #6b7280;
    font-size: 0.875rem;
    line-height: 1.5;
    margin-bottom: 1rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  
  .product-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  
  .product-price {
    font-size: 1.25rem;
    font-weight: 700;
    color: #10b981;
  }
  
  .buy-button {
    background-color: #10b981;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    
    &:hover {
      background-color: #059669;
      transform: scale(1.02);
    }
  }
}
</style>
